import * as components from './components'

// 类型
import type { App, Plugin } from 'vue';

// 插件选项接口
export interface HsaUIOptions {
    prefix?: string
    // 可以添加其他全局配置选项
}

// 创建插件安装函数
const createInstall = (options: HsaUIOptions = {}): Plugin => {
    return {
        install(app: App) {
            // 注册所有组件
            Object.values(components).forEach(component => {
                if (component.name) {
                    const name = options.prefix
                        ? `${options.prefix}${component.name}`
                        : component.name
                    app.component(name, component)
                }
            })

            // 注册全局属性
            app.config.globalProperties.$HSAUI = {
                version: '1.0.0',
                ...options
            }
        }
    }
}

export default createInstall